package org.fusionide.builder.parsers.cfml;

public class Variable {
	private String name;

	private String scope;

	private String hint;

	private int lineNumber;

	private boolean varScoped = false;

	private int type = string;

	public static final int any = 0;

	public static final int array = 1;

	public static final int binary = 2;

	public static final int booleantype = 3;

	public static final int date = 4;

	public static final int guid = 5;

	public static final int numeric = 6;

	public static final int query = 7;

	public static final int string = 8;

	public static final int struct = 9;

	public static final int uuid = 10;

	public static final int xml = 11;

	public static final int function = 12;

	public static int getType(String type) {
		if (type == null)
			return any;
		if (type.equalsIgnoreCase("any"))
			return any;
		if (type.equalsIgnoreCase("array"))
			return array;
		if (type.equalsIgnoreCase("binary"))
			return binary;
		if (type.equalsIgnoreCase("boolean"))
			return booleantype;
		if (type.equalsIgnoreCase("date"))
			return date;
		if (type.equalsIgnoreCase("guid"))
			return guid;
		if (type.equalsIgnoreCase("numeric"))
			return numeric;
		if (type.equalsIgnoreCase("query"))
			return query;
		if (type.equalsIgnoreCase("string"))
			return string;
		if (type.equalsIgnoreCase("struct"))
			return struct;
		if (type.equalsIgnoreCase("uuid"))
			return uuid;
		if (type.equalsIgnoreCase("xml"))
			return xml;
		return any;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append(name);
		sb.append("\n");
		sb.append(scope);
		sb.append("\n");
		sb.append(lineNumber);
		sb.append("\n");
		sb.append(varScoped);
		sb.append("\n");
		sb.append(type);
		sb.append("\n");
		return sb.toString();
	}

	public Variable(String name, int lineNumber, boolean varScoped) {
		this.name = name;

		if (name.lastIndexOf(".") != -1)
			this.scope = name.substring(0, name.lastIndexOf(".") + 1);
		else
			this.scope = "";

		this.lineNumber = lineNumber;
		this.varScoped = varScoped;
		this.type = any;
	}

	public Variable(String name, int lineNumber, boolean varScoped, int type) {
		this.name = name;

		if (name.lastIndexOf(".") != -1)
			this.scope = name.substring(0, name.lastIndexOf(".") + 1);
		else
			this.scope = "";

		this.lineNumber = lineNumber;
		this.varScoped = varScoped;
		this.type = type;
	}

	public String getScope() {
		return scope;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getLineNumber() {
		return lineNumber;
	}

	public void setLineNumber(int lineNumber) {
		this.lineNumber = lineNumber;
	}

	public boolean isVarScoped() {
		return varScoped;
	}

	public void setVarScoped(boolean varScoped) {
		this.varScoped = varScoped;
	}

	public String getTypeDescription() {
		if (type == any)
			return "any";
		if (type == array)
			return "array";
		if (type == binary)
			return "binary";
		if (type == booleantype)
			return "boolean";
		if (type == date)
			return "date";
		if (type == function)
			return "function";
		if (type == guid)
			return "guid";
		if (type == numeric)
			return "numeric";
		if (type == query)
			return "query";
		if (type == string)
			return "string";
		if (type == struct)
			return "struct";
		if (type == uuid)
			return "uuid";
		if (type == xml)
			return "xml";
		return "any";
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getHint() {
		if (hint == null)
			return getTypeDescription();
		return hint;
	}

	public void setHint(String hint) {
		this.hint = hint;
	}
}
